//
//  HouseTypeView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/20.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HouseTypeView.h"
#import "HouseTypeCellModel.h"
#import "UIImageView+WebCache.h"
#import "StringTool.h"
#import "config.h"
#import "API.h"


@interface HouseTypeView ()

//房屋 图片
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
//房屋类型 ＋ 几间卧室
@property (weak, nonatomic) IBOutlet UILabel *HouseType;
//房屋面积
@property (weak, nonatomic) IBOutlet UILabel *HouseArea;
//卧室数量
@property (weak, nonatomic) IBOutlet UILabel *WoShiNum;
//卫浴数量
@property (weak, nonatomic) IBOutlet UILabel *WeiYuNum;
//车库数量
@property (weak, nonatomic) IBOutlet UILabel *CheKuNum;
//现房
@property (weak, nonatomic) IBOutlet UILabel *HouseTag;

@property (weak, nonatomic) IBOutlet UILabel *houseImage;


//期房，现房，样板房的图片
@property (weak, nonatomic) IBOutlet UIImageView *houseTypeImg1;
//有无房型图的图片
@property (weak, nonatomic) IBOutlet UIImageView *houseTypeImg2;
@property (weak, nonatomic) IBOutlet UIImageView *houseTypeImg3;
- (IBAction)clickBtn:(UIButton *)sender;

@property (strong, nonatomic) HouseTypeCellModel *model;

@end
@implementation HouseTypeView



+(instancetype)houseTypeViewInitWithXib
{
    
    return [[[NSBundle mainBundle]loadNibNamed:@"HouseTypeViews" owner:nil options:nil]lastObject];

}


-(void)setData:(HouseTypeCellModel *)model
{
    
    _model = model;
    
    self.HouseType.text = [NSString stringWithFormat:@"%@:%@间卧室%@间浴室",model.typeName,model.bedRoom,model.bathRoom];
    self.HouseArea.text = [NSString stringWithFormat:@"房屋面积:%zd㎡",[model.areaMi integerValue]];
    self.WoShiNum.text = [NSString stringWithFormat:@"%@间",model.bedRoom];
    self.WeiYuNum.text = [NSString stringWithFormat:@"%@间",model.bathRoom];
    self.CheKuNum.text = [NSString stringWithFormat:@"%@间",model.garage];
    //有房型图
    self.houseImage.text = model.houseTypePicName;
    if ([model.houseTypePicName isEqual:@"有房型图"])
    {
        [self.houseTypeImg2 setImage:[UIImage  imageNamed:@"fangxing_icon_b"]];
    }else
    {
        [self.houseTypeImg2 setImage:[UIImage  imageNamed:@"fangxing_icon_a"]];
    }
    //现房
    self.HouseTag.text = model.houseTypeName;
    
    
    
    if ([model.houseTypeName isEqual:@"现房"])
    {
        self.HouseTag.textColor = [UIColor colorWithRed:225/255.0 green:39/255.0 blue:39/255.0 alpha:1];
        [self.houseTypeImg1 setImage:[UIImage  imageNamed:@"xianfang_icon"]];
        [self.houseTypeImg3 setImage:[UIImage  imageNamed:@"xianfang_a_icon"]];
    }
    else if ([model.houseTypeName isEqual:@"期房"])
    {
        self.HouseTag.textColor = [UIColor colorWithRed:227/255.0 green:64/255.0 blue:39/255.0 alpha:1];
        [self.houseTypeImg1 setImage:[UIImage  imageNamed:@"qifang_icon"]];
        [self.houseTypeImg3 setImage:[UIImage  imageNamed:@"qifang_a_icon"]];
    }
    else if ([model.houseTypeName isEqual:@"已售"])
    {
        self.HouseTag.textColor = UIColorFromRGB(0x999999);
        [self.houseTypeImg1 setImage:[UIImage  imageNamed:@"yishou"]];
        [self.houseTypeImg3 setImage:[UIImage  imageNamed:@"icon1"]];
    }
    
    NSString *strUrl;
    if ([StringTool isBlankString:model.thumb]) {
        strUrl = @"";
    }else{
        
        strUrl = [API imgUrlMake:model.thumb];
    }
    
    

      [self.imageView setBackgroundColor:NoImgColor];
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:strUrl] placeholderImage:nil];
   
   
    
    
}

+(CGFloat)getHight{
    
    static HouseTypeView *view = nil;
    
    static dispatch_once_t predicate;
    
    dispatch_once(&predicate, ^{
        
       view = [HouseTypeView houseTypeViewInitWithXib];
        
    });
    
    
    CGFloat height = [view systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
    return height+1;
}


- (IBAction)clickBtn:(UIButton *)sender
{
    [self.delegate houseTypeViewDidClickBtn:self.model.housingId];

//    if (self.delegate && [self.delegate respondsToSelector:@selector(houseTypeViewDidClickBtn:)]) {
//            }
}
@end
